<?php
/*------------------------------------------------------------------------------
this file is part of Web Application Kit http://webappkit.net
Copyright (C) 2006 J.Ducastel <jducastel@jducastel.fr>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
------------------------------------------------------------------------------*/

/**
* filesystem access core service
* @author J.Ducastel <jducastel@jducastel.fr>
* @version 
*/
class wakFileSystem extends wakService {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	* constructor alias
	* @access public
	*/
	function wakFileSystem() {
		$this->__construct();
	}/**/
	
	/**
	* "real" constructor
	* @access public
	*/
	function __construct() {
		parent::__construct();
		// getting debug
		$this->debug=&wak::getservice('wakdebug');
		// don't require libraries at this stage, this may crash if this is called by waklib
	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* lists directory content : files and subdirs
	* @param string $path
	* @param bool $recursive
	* @access public
	* @return array
	*/
	function & dirList($path,$recursive=false) {
		if (!is_dir($path)) {
			$debug->notice("$path is not a directory");
			return false;
		}
		$result=array();
		$d=dir($path); $n=0;
		while ($subpath=$d->read()) {
			$n++; if ($n>500) break;
			if ($subpath=='.' or $subpath=='..') continue;
			$result[]=$subpath;
			if (!$recursive or !is_dir($subpath))
				continue;
			// recursion on directories
			$subresult=$this->dirList($subpath,true);
			$result=array_merge($result,$subresult);
		}
		return $result;
	}/**/
	
	/**
	* regular expression search on directory's file names
	* @param
	* @access public
	* @return array file relative paths
	*/
	function dirRegexSearchName($path,$regex,$recursive=false) {
		$folder=pathnode::getnode($path);
		$nodes=$folder->regexSearchName($regex,$recursive);
		$result=array();
		foreach ($nodes as $node) {
			$result[]=$node->getRelativePath();
		}
		return $result;
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var type desc
	*/
	//var //
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
}
?>
